import { MPaginationRes, MPaginationReq } from "@/modules/common"
import { MCustomer, Muser, MIcCard } from "../entities/account.model"
import http from '@/utils/request'

class AccountServiceTemp {
    getCustomerList(param: MPaginationReq): Promise<MPaginationRes> {
        return http.post('/yxd/oa/customer/page', param).then((res: any) => {
            res as MPaginationRes;
            return Promise.resolve({
                dataList: res.data,
                total: res.total
            })
        })
    }

    editCustomer(form: MCustomer) {
        return http.post(`/yxd/oa/customer/${form.id ? 'update' : 'add'}`, form)
    }

    getIcCardList(param: MPaginationReq): Promise<MPaginationRes> {
        return http.post('/yxd/oa/customer/iCCard/page', param).then((res: any) => {
            res as MPaginationRes;
            return Promise.resolve({
                dataList: res.data,
                total: res.total
            })
        })
    }

    editIcCard(form: MIcCard) {
        return http.post(`/yxd/oa/customer/iCCard/${form.id ? 'update' : 'add'}`, form)
    }

    getUserList(param: MPaginationReq): Promise<MPaginationRes> {
        return http.post('/yxd/oa/user/page', param).then((res: any) => {
            res as MPaginationRes;
            return Promise.resolve({
                dataList: res.data,
                total: res.total
            })
        })
    }
    editUser(form: Muser) {
        return http.post(`/yxd/oa/user/${form.id ? 'update' : 'add'}`, form)
    }
    modifyPassword(form: {
        newPassword: String,
        oldPassword: String,
        token: String
    }) {
        return http.post('/yxd/oa/user/changePassword', form)
    }
    resetPassword(id: string) {
        return http.get('/yxd/oa/user/resetPassword', { params: { id } })
    }
}
const AccountService = new AccountServiceTemp();
export { AccountService }